#!/bin/bash
source /home/shell/util.sh

apt install -y curl gnupg2 ca-certificates lsb-release

echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx"| tee /etc/apt/sources.list.d/nginx.list
sleep 1s
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx

download /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key
gpg --dry-run --quiet --import --import-options show-only /tmp/nginx_signing.key
mv /tmp/nginx_signing.key /etc/apt/trusted.gpg.d/nginx_signing.asc
apt update
apt install -y nginx
# 清理
rm -rf /etc/apt/sources.list.d/nginx.list
rm -rf /etc/apt/trusted.gpg.d/nginx_signing.asc
rm -rf /etc/apt/preferences.d/99nginx

## 配置nginx
mkdir -p /var/log/webapps/nginx/

sed -ri "s/\/var\/log\/nginx\/error.log/\/var\/log\/webapps\/nginx\/admin_error.log/" /etc/nginx/nginx.conf
sed -ri "s/\/var\/log\/nginx\/access.log/\/var\/log\/webapps\/nginx\/access.log/" /etc/nginx/nginx.conf
sed -ri "s/user\s*nginx;/user  root;/" /etc/nginx/nginx.conf

# setsebool -P httpd_read_user_content 1

## 启动nginx
systemctl start nginx
systemctl enable nginx
systemctl is-enabled nginx
systemctl status nginx

sleep 1s
## nginx进程信息
ps aux|grep nginx